<template>
  <div>
    <el-form :model="RoleForm" :rules="Roleriles" ref="RoleForm" label-width="100px" class="demo-RoleForm">
      <el-form-item label="角色名称" prop="roleName">
        <el-input v-model="RoleForm.roleName"></el-input>
      </el-form-item>
      <el-form-item label="角色简介" prop="roleContent">
        <el-input v-model="RoleForm.roleContent"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { updateRole, getFid } from "@/api/role";

export default {
  data() {
    return {
      RoleForm: {
        id: 0,
        roleName: "",
        roleContent: "",
      },
      Roleriles: {
        roleName: [
          { required: true, message: "请输入角色名称", trigger: "blur" },
        ],
        roleContent: [
          { required: true, message: "请输入角色简介", trigger: "blur" },
        ],
      },
      RoleId: 0,
    };
  },
  props: {
    Rid: {
      type: Number
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs.RoleForm.validate((valid) => {
        if (valid) {
          updateRole(this.RoleForm.id, this.RoleForm).then((res) => {
            if (res.data) {
              this.$message.success("修改成功");
              location.reload();
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    Getfind(id) {
      getFid(id).then((res) => {
        this.RoleForm.id = id;
        this.RoleForm = res.data;
      });
    },
  },
  created() {
    this.RoleId = this.Rid;
    console.log(this.RoleId);
    this.Getfind(this.RoleId)
  },
};
</script>